function projectStruct = gui_load_file(hObject, source, frame_start, ...
    frame_end, workDir)
%
%frames = [];
projectStruct = [];

if(nargin < 5)
    workDir = '';
end

wb = waitbar(0.1, 'Analyzing input');

try
    if(isdir(source))
        % Find all files in the input directory and their number.
        fileListing = dir(source);
        numFiles = numel(fileListing);

        template = '0';
        % Find the indices of all files residing in the input directory that have
        % the same prefix and extension as the given input file name.
        for k = 1:numFiles
            if(regexpi(fileListing(k).name,'\.dpx$'))
                template = [source fileListing(k).name];
                break
            end
        end

        if(template == '0')
            errordlg('No DPX files found.', 'Error', 'modal')
            return
        end
    else
        template = source;
    end
    
    if(isempty(workDir))
        workDir = fileparts(template);
        workDir = [workDir filesep];
    end
    
    %[t_path, t_name, t_ext] = fileparts(template);
    %if(strcmpi(t_ext,'.dpx'))
    %    h = waitbar(0.1,'Reading frames...');
    %    [inDirPath, inFilePrefix, idxFieldLen, inFileExt, fileIdxArr] = ...
    %        getFileSequenceFromRepresetative(template, frame_start, frame_end);
    %    close(h);
    %else
    %    warndlg('Only DPX frames are supported at this time.');
    %    return;
    %end
    
    projectStruct = setUpFactoryPresets();
    projectStruct.outputDir = workDir;
    projectStruct = analyzeVideoInput(template, projectStruct);

    close(wb);
    
catch exception
    close(wb);
    gui_exception(exception);
    return
end

try
    if(strncmpi(projectStruct.inFile.kind, 'unknown', 7))
        projectStruct = [];
        er = errordlg('Unknown film format','Error','modal');
        uiwait(er);
    end
catch exception
    gui_exception(exception);
end
